package pl.streamsoft.currencyApp.App;

import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import pl.streamsoft.currencyApp.model.Country;
import pl.streamsoft.currencyApp.model.Currency;
import pl.streamsoft.currencyApp.parser.XMLCurrencyParser;
import pl.streamsoft.currencyApp.services.CountryService;
import pl.streamsoft.currencyApp.services.CurrencyService;
import pl.streamsoft.currencyApp.services.ICountryService;
import pl.streamsoft.currencyApp.stream.InputStreamReader;

public class CurrencyAppTest {

	/**
	 * @param args
	 * pawel000000000000
	 */
	public static void main(String[] args) {
		try {
			CurrencyService curService =
					new CurrencyService(new InputStreamReader(new URL("http://nbp.pl/kursy/xml/LastA.xml").openStream(), "ISO-8859-2"), new XMLCurrencyParser());
			
			List<Currency> lista = curService.getListOfCurrencies();
			
			for(Currency el: lista){
				System.out.println("Name of the currency: "+el.getName()+ ", code: "+el.getCurrencyCode()+ ", converter: "+ el.getConverter()+ ", average rate: "+el.getAverageRate());
			}
			
			Country countryPoland = new Country();
			countryPoland.setName("POLAND");
			List<Currency> listOfPolandCurrencies = new ArrayList<Currency>();
			listOfPolandCurrencies.add(curService.getCurrencyByName("bat (Tajlandia)"));
			listOfPolandCurrencies.add(curService.getCurrencyByCode("USD"));
			for(Currency el: listOfPolandCurrencies){
				countryPoland.getCurrencyList().add(el);
			}
			
			Country countryUkraine = new Country();
			countryUkraine.setName("UKRAINE");
			List<Currency> listOfUkraineCurrencies = new ArrayList<Currency>();
			listOfUkraineCurrencies.add(curService.getCurrencyByName("dolar ameryka�ski"));
			listOfUkraineCurrencies.add(curService.getCurrencyByCode("HKD"));
			for(Currency el: listOfUkraineCurrencies){
				countryUkraine.getCurrencyList().add(el);
			}
			
			List<Country> listOfCountries = new ArrayList<Country>();
			listOfCountries.add(countryPoland);
			listOfCountries.add(countryUkraine);
			
			ICountryService countryService = new CountryService(listOfCountries);
			Country countryFrance = new Country();
			countryFrance.setName("FRANCE");
			List<Currency> listOfFranceCurrency = new ArrayList<Currency>();
			listOfFranceCurrency.add(curService.getCurrencyByName("funt szterling"));
			listOfFranceCurrency.add(curService.getCurrencyByCode("EUR"));
			for(Currency el: listOfFranceCurrency){
				countryFrance.getCurrencyList().add(el);
			}
			countryService.addCountryToList(countryFrance);
			
			System.out.println("--------------------------------------------------------------------------------------------------");
			
			Country countryP = countryService.getCountryByName("POLAND");
			System.out.println("POLISH CURRENCIES ARE:");
			for(Currency el: countryP.getCurrencyList()){
				System.out.println("Name of the currency: "+el.getName()+ ", code: "+el.getCurrencyCode()+ ", converter: "+ el.getConverter()+ ", average rate: "+el.getAverageRate());
			}
			
			System.out.println("--------------------------------------------------------------------------------------------------");
			
			List<Country> listOfC = countryService.getListOfCountries();
			for(Country el: listOfC){
				System.out.println("Name of country is: "+el.getName());
				for(Currency elem: el.getCurrencyList()){
					System.out.println("Name of the currency: "+elem.getName()+ ", code: "+elem.getCurrencyCode()+ ", converter: "+ elem.getConverter()+ ", average rate: "+elem.getAverageRate());
				}
			}
		} 
		catch (Exception e) {
			e.printStackTrace();
		}
		
	}

}
